package com.example.cybz.sys.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.cybz.common.result.Result;
import com.example.cybz.model.sys.RegionWare;
import com.example.cybz.sys.service.RegionWareService;
import com.example.cybz.vo.sys.RegionWareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 城市仓库关联表 前端控制器
 * </p>
 *
 * @author mhwssad
 * @since 2025-06-26
 */
@Api(tags = "开通区域接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/sys/regionWare")
public class RegionWareController {
    private final RegionWareService regionWareService;

    @ApiOperation("开通区域列表")
    @GetMapping("/{current}/{limit}")
    public Result< Page<RegionWare>> list(@PathVariable Long current, @PathVariable Long limit, RegionWareQueryVo regionWareQueryVo) {
        Page<RegionWare> pageParam = new Page<>(current, limit);
        Page<RegionWare> regionModel =  regionWareService.selectPageRegionWar(pageParam, regionWareQueryVo);
        return Result.ok(regionModel);
    }

    @ApiOperation("添加开通区域")
    @PostMapping("save")
    public Result<Object> addRegionWare(@RequestBody RegionWare regionWare){
        boolean saveRegionWare = regionWareService.saveRegionWare(regionWare);
        return saveRegionWare ? Result.ok() : Result.fail();
    }

    @ApiOperation("删除开通区域")
    @DeleteMapping("remove/{id}")
    public Result<Void> remove(@PathVariable("id") Long id){
        boolean removeById = regionWareService.removeById(id);
        return removeById ? Result.ok() : Result.fail();
    }

    @ApiOperation("取消开通")
    @GetMapping("updateStatus/${id}/${status}")
    public Result<Void> updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status){
        boolean updateByStatus = regionWareService.updateByStatus(id, status);
        return updateByStatus ? Result.ok() : Result.fail();
    }

}

